package com.novabluetooth.services.servicedevices;

import java.util.List;
import java.util.UUID;

import com.novabluetooth.services.TJBluetoothLeService;

import android.bluetooth.BluetoothGattDescriptor;
import android.bluetooth.BluetoothGattService;
import android.util.Log;

/**
 * 鱼跃血压计760
 * 
 * @author nova
 *
 */
public class XueYaYuYue760Service extends TJBluetoothLeService {
	/**
	 * 鱼跃血压计
	 */
	public final static UUID serviceYUYUEXUEYAUUID = UUID.fromString("00001810-0000-1000-8000-00805f9b34fb");
	public final static UUID readCharactYUYUEXUEYAUUID = UUID.fromString("00002a36-0000-1000-8000-00805f9b34fb");
	public final static UUID bloodIndicateCharactUUID = UUID.fromString("00002a35-0000-1000-8000-00805f9b34fb");
	
	@Override
	public void servicesDiscovered() {
		super.servicesDiscovered();
		BluetoothGattService gattService = mBluetoothGatt.getService(serviceYUYUEXUEYAUUID);
		readGattCharact = gattService.getCharacteristic(bloodIndicateCharactUUID);
		mBluetoothGatt.setCharacteristicNotification(readGattCharact, true);
		mBluetoothGatt.readCharacteristic(readGattCharact);
		List<BluetoothGattDescriptor> descriptors2 = readGattCharact.getDescriptors();
		for (BluetoothGattDescriptor dp1 : descriptors2) {
			dp1.setValue(BluetoothGattDescriptor.ENABLE_INDICATION_VALUE);
			Log.d(TAG, "writing enabledescriptor:" + mBluetoothGatt.writeDescriptor(dp1));
		}
	}

	@Override
	public boolean isRightData(byte[] buffer) {
		super.isRightData(buffer);

		int gaoya = buffer[1] & 0xFF;
		// 低压
		int diya = buffer[3] & 0xFF;
		// 心率
		int xinlv = buffer[14] & 0xFF;
		checkData = gaoya + ";" + diya + ";" + xinlv;
		Log.e("BluetoothLeService", "血压出结果" + checkData);
		ifSuccess = true;
		disconnect();
		return ifSuccess;

	}

	@Override
	public void closeDevice() {
		super.closeDevice();
	}

}
